package progetto6.jade;

import java.util.Random;

public class MinorityScoreStrategy extends ScoreDependentStrategy {
	
	private static final long serialVersionUID = 3752516981817630007L;
	private final int nStep;
	private int iteration = 0;
	private Random random = new Random();

	public MinorityScoreStrategy(int n, int perc) {
		nStep = (n*perc)/100;
	}

	@Override
	public Choice getNext() {
		if(iteration < nStep){
			double r = random.nextDouble();
			if (r > 0.5) {
				lastChoice = Choice.C;
			} else {
				lastChoice = Choice.D;
			}
		}else{
			if(score[0] < score[1]){
				lastChoice = Choice.D;
			}else{
				lastChoice = Choice.C; 
			}
		}
		iteration++;
		return lastChoice;
	}

	@Override
	public String toString() {
		return "MinorityScoreStrategy[nStep:"+nStep+"]";
	}
}
